﻿using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Looptribe.WinRT.Toolkit.Controls.CalendarPrimitives
{
    public class CalendarDay : Control
    {
        #region VisualStates

        internal const string StateRegularDay = "RegularDay";
        internal const string StateNonRegularDay = "NonRegularDay";

        #endregion

        #region ItemTemplate

        public static readonly DependencyProperty ItemTemplateProperty =
            DependencyProperty.Register(
                "ItemTemplate",
                typeof (DataTemplate),
                typeof (CalendarDay),
                null);

        public DataTemplate ItemTemplate
        {
            get { return (DataTemplate) GetValue(ItemTemplateProperty); }
            set { SetValue(ItemTemplateProperty, value); }
        }

        #endregion

        private DayData Data
        {
            get { return (DayData) DataContext; }
        }

        public CalendarDay()
        {
            DefaultStyleKey = typeof (CalendarDay);
        }

        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ChangeVisualState(false);
        }

        internal void ChangeVisualState(bool useTransitions)
        {
            VisualStateManager.GoToState(this, Data.IsRegularDay ? StateRegularDay : StateNonRegularDay, useTransitions);
        }
    }
}
